<{include file="Public/head.tpl"}>
<{include file="Public/header.tpl"}>
<{include file="Public/siderbar.tpl"}>
<{include file="Public/contentheader.tpl"}>

    <!-- Main content -->
    <section class="content">

      <div class="col-md-6">
        <!-- Horizontal Form -->
          <div class="box box-info">
            <div class="box-header with-border">
              <h3 class="box-title">请设置角色的权限信息</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form class="form-horizontal">
              <div class="box-body">
                <table class="table" id="power_tree">
                  <{$power}>
                </table>
              </div>
              <!-- /.box-body -->
              <div class="box-footer">
                <input type="hidden" id="id" value="<{$data->id}>" />
                <a href="/admin/power/list" class="btn btn-default">取消</a>
                <button type="button" class="btn btn-info pull-right" onclick="set();">确定</button>
              </div>
              <!-- /.box-footer -->
            </form>
          </div>
          <!-- /.box -->
       </div>

    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  
<{include file="Public/footer.tpl"}>
<script>
function set() {
  bootbox.setLocale("zh_CN");
  var posturl = window.location.href;
  var powerid = new Array();
  $("input[type=checkbox]").each(function(){
      if(this.checked){
        powerid.push($(this).val());
      }
  }); 
  $.ajax({
  url : posturl,
  type : 'post',
  data : 'powerid=' + powerid.join(","),
  success : function(data) {
    var ret = JSON.parse(data);
      if (ret.status == 1) {
        bootbox.alert(ret.data);
        setTimeout(function(){window.location.href="/admin/role/list"}, 2000);
      } else {
        bootbox.alert(ret.data);
      }
    }
  }); 
}


function checknode(obj) {
    var chk = $("input[type='checkbox']"); 
    var count = chk.length;
    var num = chk.index(obj);
    var level_top = level_bottom = chk.eq(num).attr('level');
    for (var i = num; i >= 0; i--) {
        var le = chk.eq(i).attr('level');
        if (eval(le) < eval(level_top)) {
            chk.eq(i).attr("checked", true);
            var level_top = level_top - 1;
        }
    }
    for (var j = num + 1; j < count; j++) {
        var le = chk.eq(j).attr('level');
        if (chk.eq(num).attr("checked") == "checked") {
            if (eval(le) > eval(level_bottom)){
            	chk.eq(j).attr("checked", true);
            }
            else if (eval(le) == eval(level_bottom)){
            	break;
            }
        } else {
            if (eval(le) > eval(level_bottom)){
            	chk.eq(j).attr("checked", false);
            }else if(eval(le) == eval(level_bottom)){
            	break;
            }
        }
    }
}
</script>
</body>
</html>